package com.feisuanyz.controller;

import com.feisuanyz.constant.ResultCodeConstant;
import com.feisuanyz.pojo.domain.MealSelectionDO;
import com.feisuanyz.pojo.dto.CreateGroup;
import com.feisuanyz.pojo.dto.DeleteGroup;
import com.feisuanyz.pojo.dto.MealSelectionDTO;
import com.feisuanyz.pojo.dto.RestResult;
import com.feisuanyz.pojo.dto.UpdateGroup;
import com.feisuanyz.pojo.query.MealSelectionQuery;
import com.feisuanyz.pojo.query.QueryGroup;
import com.feisuanyz.pojo.vo.PageResult;
import com.feisuanyz.service.MealSelectionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.lang.Boolean;
import java.lang.Long;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 历史记录管理
 *
 * @author Chenke Zhao
 * @date 2025-03-06 10:18:05
 */
@Tag(name = "历史记录管理")
@RequestMapping("mealSelection")
@RestController
public class MealSelectionController {

    @Autowired
    private MealSelectionService mealSelectionService;

    /**
     * records
     *
     * @param query 食物选择查询入参实体类
     * @return
     */
    @RequestMapping(value = "/records", method = RequestMethod.GET)
    @Operation(summary = "records")
    public RestResult<PageResult<MealSelectionDO>> getMealSelectionRecords(@Validated(QueryGroup.class) MealSelectionQuery query) {
        PageResult<MealSelectionDO> result = mealSelectionService.getMealSelectionRecords(query);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * add
     *
     * @param mealSelectionDTO 食物选择记录入参实体类
     * @return
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @Operation(summary = "add")
    @ResponseBody
    public RestResult<Boolean> addMealSelection(@RequestBody @Validated(CreateGroup.class) MealSelectionDTO mealSelectionDTO) {
        Boolean result = mealSelectionService.addMealSelection(mealSelectionDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * update
     *
     * @param mealSelectionDTO 食物选择记录入参实体类
     * @return
     */
    @RequestMapping(value = "/update", method = RequestMethod.PUT)
    @Operation(summary = "update")
    @ResponseBody
    public RestResult<Boolean> updateMealSelection(@RequestBody @Validated(UpdateGroup.class) MealSelectionDTO mealSelectionDTO) {
        Boolean result = mealSelectionService.updateMealSelection(mealSelectionDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * delete
     *
     * @param selectionId
     * @return
     */
    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
    @Operation(summary = "delete")
    public RestResult<Boolean> deleteMealSelection(@Validated(DeleteGroup.class) Long selectionId) {
        Boolean result = mealSelectionService.deleteMealSelection(selectionId);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }
}
